from selenium import webdriver
import time
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.options import Options

# driver = webdriver.Chrome("C:/Users/EDZ/AppData/Local/Google/Chrome/Application/chromedriver.exe")


chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
browser = webdriver.Chrome(options=chrome_options)


# 找到html文件并打开
Path_name = 'D:/Python学习-100天/Day52/selenium.html'

browser.get(Path_name)

# 将浏览器最大化
time.sleep(2)
browser.maximize_window()

# 查找元素并操作
time.sleep(2)
User_name = browser.find_element_by_css_selector('div#signup input[name="username"]').send_keys('rabbit')
time.sleep(2)
Pass_word = browser.find_element_by_css_selector('div#signup input[name="password"]').send_keys('love')
time.sleep(2)
radios = browser.find_elements_by_css_selector('div#signup input[type="checkbox"]')
for radio in radios:
    if radio.is_selected() == False:
        radio.click()


# 下拉选择 深圳
time.sleep(2)
selector=Select(browser.find_element_by_name("city"))
selector.select_by_index("3")
# selector.select_by_value("sz")

# 提交表单
time.sleep(2)
# submit = browser.find_element_by_css_selector('div#signup form').submit()
# submit = browser.find_element_by_xpath("//input[@type='submit']").submit()
submit =browser.find_element_by_xpath("//input[@type='submit']").click()
# time.sleep(10)


# 显示等待
result = WebDriverWait(browser, 10, 1).until(
    lambda x: x.find_element_by_css_selector("div#signup p").text == "注册成功")
print(result)


# 关闭浏览器
browser.quit()
